package remote{

	
	import entidades.Urgencia;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class UrgenciaRemote {
		
		public function exibirUrgencia( result:Function ):void{
			var async:AsyncToken = _remote.listUrgencia();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function buscarUrgencia(result:Function, numUrgencia:Number, urgencia:Number,
										 idStatus:Number, dtPlanejada:Date, dtCriacaoIni:Date, dtCriacaoFim:Date):void{
			var result:Function;
			var async:AsyncToken = _remote.buscarUrgencia(numUrgencia, urgencia,
				idStatus, dtPlanejada, dtCriacaoIni, dtCriacaoFim);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		public function gravarUrgencia(urgencia:Urgencia ):void{
			var result:Function;
			var async:AsyncToken = _remote.addUrgencia(urgencia);
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		//--------------------setup----------------------------//
		private var _remote:RemoteObject;
		
		public function UrgenciaRemote(){
			_remote = new RemoteObject();
			_remote.showBusyCursor = true;
			_remote.destination = 'UrgenciaService';
		}
		
		private function defaultFaultHandler(e:FaultEvent):void{
			Alert.show( "Estamos com problemas no servidor! Tente novamente mais tarde!","Urgência" );
		}
		
		private static var _instance:UrgenciaRemote;
		public static function getInstance():UrgenciaRemote{
			if(_instance == null){
				_instance = new UrgenciaRemote();
			}
			return _instance;
		}
	}
}